package kr.co.bettersoftportal.site.management.dao;

import kr.co.bettersoftportal.site.domain.Member;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;

public class MemberDaoImpl extends SqlMapClientDaoSupport implements MemberDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(MemberDaoImpl.class);

    public Member getMemberById(String id) {
        return (Member)getSqlMapClientTemplate().queryForObject("MEMBER.getMemberById", id);
    }

    public String getMemberExistById(String id) {
        return (String)getSqlMapClientTemplate().queryForObject("MEMBER.getMemberExistById", id);
    }

    public String logIn(Member member) {
        return (String)getSqlMapClientTemplate().queryForObject("MEMBER.logIn", member);
    }

    public String insertMember(Member member){
        return Integer.toString(getSqlMapClientTemplate().update("MEMBER.insertMember", member));
    }

    /**
     * 멤버 정보를 이용하여 비밀번호 수정
     *
     * @param member
     * @return
     */
    public String updatePasswordByMember(Member member){
        return Integer.toString(getSqlMapClientTemplate().update("MEMBER.updatePasswordByMember", member));
    }

    /**
     * 검색 단어로 회원 조회하기.
     *
     * @param member
     * @return
     */
    public List getMemberListBySearchword(Member member){
        return getSqlMapClientTemplate().queryForList("MEMBER.getMemberListBySearchword", member, member.getCurrentPage() * member.getPageSize(), member.getPageSize());
    }
    
    /**
     * 검색 단어로 회원 수 조회하기.
     *
     * @param member
     * @return
     */
    public String getTotalMemberCountBySearchword(Member member){
        return (String)getSqlMapClientTemplate().queryForObject("MEMBER.getTotalMemberCountBySearchword", member);
    }

    /**
     * ID 로 멤버 정보 업데이트
     *
     * @param member
     * @return
     */
    public String updateMemberByBettersoftId(Member member){
        return Integer.toString(getSqlMapClientTemplate().update("MEMBER.updateMemberByBettersoftId", member));
    }
}
